﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ajaxdatatype_Default" %>

<%@ Register Assembly="zoyobar.shared.panzer.JQueryElement" Namespace="zoyobar.shared.panzer.ui.jqueryui"
	TagPrefix="je" %>
<%@ Register Assembly="zoyobar.shared.panzer.JQueryElement" Namespace="zoyobar.shared.panzer.web.jqueryui"
	TagPrefix="je" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>Ajax 与服务器的数据类型转换</title>
	<link rel="stylesheet" type="text/css" href="../css/smoothness/jquery-ui-1.8.15.custom.css" />
	<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
	<script type="text/javascript" src="../js/jquery-ui-1.8.15.custom.min.js"></script>
	<link rel="stylesheet" type="text/css" href="../css/main.css" />
</head>
<body>
	<form id="formAjaxDataType" runat="server">
	<div class="title purple-title">
		Ajax 与服务器的数据类型转换
		<iframe src="../about.htm" frameborder="0" height="160" width="100%" allowtransparency="true" scrolling="no"></iframe>
	</div>
	<div class="content">
		<h2>
			准备
		</h2>
		<blockquote>
			请确保已经阅读 <a href="../returnjson/Default.aspx">在不同的 .NET 版本中返回 JSON</a>. 本页代码符合 .NET 2.0 版本, 其它版本请另作调整.<br />
			<br />
			<strong>详细说明请参考:</strong> <a href="http://code.google.com/p/zsharedcode/wiki/AjaxDataType"
				target="_blank">code.google.com/p/zsharedcode/wiki/AjaxDataType</a><br />
			<br />
			<strong>视频解说:</strong> <a href="http://www.tudou.com/programs/view/dlC1WPtjXEE/"
				target="_blank">www.tudou.com/programs/view/dlC1WPtjXEE/</a>
		</blockquote>
		<h2>
			字符串
		</h2>
		<blockquote>
			StringToString 是拥有 string 类型参数的服务器端方法.<br />
			<br />
			<strong>字符串:</strong>
			<input type="text" id="txtString1" />
			<je:Button ID="cmdString1" runat="server" Label="传递字符串到 string StringToString(string)">
				<ClickAsync Url="webservice.asmx" MethodName="StringToString" Success="
				function(data){
					$('#lblString1').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Selector" Value="'#txtString1'" DataType="String" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblString1"></p>
			服务端会将数值转化为字符串, <je:Button ID="cmdString2" runat="server" Label="传递数值 123 到 string StringToString(string)">
				<ClickAsync Url="webservice.asmx" MethodName="StringToString" Success="
				function(data){
					$('#lblString2').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="123" DataType="Number" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblString2"></p>
			服务端会将布尔值转化为字符串, <je:Button ID="cmdString3" runat="server" Label="传递布尔值 false 到 string StringToString(string)">
				<ClickAsync Url="webservice.asmx" MethodName="StringToString" Success="
				function(data){
					$('#lblString3').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="false" DataType="Boolean" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblString3"></p>
			客户端将日期转化为字符串, <je:Button ID="cmdString4" runat="server" Label="传递当前日期的字符串到 string StringToString(string)">
				<ClickAsync Url="webservice.asmx" MethodName="StringToString" Success="
				function(data){
					$('#lblString4').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="new Date()" DataType="Date" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblString4"></p>
		</blockquote>
		<h2>
			数值
		</h2>
		<blockquote>
			IntToString 是拥有 string 类型参数的服务器端方法.<br />
			<br />
			<strong>字符串, 输入不能转化为数字的字符串将导致错误:</strong>
			<input type="text" id="txtInt1" />
			<je:Button ID="cmdInt1" runat="server" Label="传递字符串到 string IntToString(int)">
				<ClickAsync Url="webservice.asmx" MethodName="IntToString" Success="
				function(data){
					$('#lblInt1').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				" Error="
				function(data){
					alert(data.responseText);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Selector" Value="'#txtInt1'" DataType="String" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblInt1"></p>
			<je:Button ID="cmdInt2" runat="server" Label="传递数值 123 到 string IntToString(int)">
				<ClickAsync Url="webservice.asmx" MethodName="IntToString" Success="
				function(data){
					$('#lblInt2').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="123" DataType="Number" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblInt2"></p>
			<je:Button ID="cmdInt3" runat="server" Label="传递布尔值 false 到 string IntToString(int)">
				<ClickAsync Url="webservice.asmx" MethodName="IntToString" Success="
				function(data){
					$('#lblInt3').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				" Error="
				function(data){
					alert(data.responseText);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="false" DataType="Boolean" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblInt3"></p>
			<je:Button ID="cmdInt4" runat="server" Label="传递当前日期的字符串到 string IntToString(int)">
				<ClickAsync Url="webservice.asmx" MethodName="IntToString" Success="
				function(data){
					$('#lblInt4').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				" Error="
				function(data){
					alert(data.responseText);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="new Date()" DataType="Date" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblInt4"></p>
		</blockquote>
		<h2>
			布尔值
		</h2>
		<blockquote>
			BoolToString 是拥有 bool 类型参数的服务器端方法.<br />
			<br />
			<strong>字符串, 输入 true/false 以外的字符串将导致错误:</strong>
			<input type="text" id="txtBool1" />
			<je:Button ID="cmdBool1" runat="server" Label="传递字符串到 string BoolToString(bool)">
				<ClickAsync Url="webservice.asmx" MethodName="BoolToString" Success="
				function(data){
					$('#lblBool1').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				" Error="
				function(data){
					alert(data.responseText);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Selector" Value="'#txtBool1'" DataType="String" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblBool1"></p>
			<je:Button ID="cmdBool2" runat="server" Label="传递数值 0 到 string BoolToString(bool)">
				<ClickAsync Url="webservice.asmx" MethodName="BoolToString" Success="
				function(data){
					$('#lblBool2').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				" Error="
				function(data){
					alert(data.responseText);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="0" DataType="Number" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblBool2"></p>
			<je:Button ID="cmdBool3" runat="server" Label="传递布尔值 false 到 string BoolToString(bool)">
				<ClickAsync Url="webservice.asmx" MethodName="BoolToString" Success="
				function(data){
					$('#lblBool3').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="false" DataType="Boolean" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblBool3"></p>
			<je:Button ID="cmdBool4" runat="server" Label="传递当前日期的字符串到 string BoolToString(bool)">
				<ClickAsync Url="webservice.asmx" MethodName="BoolToString" Success="
				function(data){
					$('#lblBool4').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				" Error="
				function(data){
					alert(data.responseText);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="new Date()" DataType="Date" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblBool4"></p>
		</blockquote>
		<h2>
			日期
		</h2>
		<blockquote>
			DateToString 是拥有 DateTime 类型参数的服务器端方法.<br />
			<br />
			<strong>字符串, 输入空或日期形式以外的字符串将导致错误:</strong>
			<input type="text" id="txtDate1" />
			<je:Button ID="cmdDate1" runat="server" Label="传递字符串到 string DateToString(DateTime)">
				<ClickAsync Url="webservice.asmx" MethodName="DateToString" Success="
				function(data){
					$('#lblDate1').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				" Error="
				function(data){
					alert(data.responseText);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Selector" Value="'#txtDate1'" DataType="String" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblDate1"></p>
			<je:Button ID="cmdDate2" runat="server" Label="传递数值 0 到 string DateToString(DateTime)">
				<ClickAsync Url="webservice.asmx" MethodName="DateToString" Success="
				function(data){
					$('#lblDate2').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				" Error="
				function(data){
					alert(data.responseText);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="0" DataType="Number" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblDate2"></p>
			<je:Button ID="cmdDate3" runat="server" Label="传递布尔值 false 到 string DateToString(DateTime)">
				<ClickAsync Url="webservice.asmx" MethodName="DateToString" Success="
				function(data){
					$('#lblDate3').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				" Error="
				function(data){
					alert(data.responseText);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="false" DataType="Boolean" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblDate3"></p>
			<je:Button ID="cmdDate4" runat="server" Label="传递当前日期的字符串到 string DateToString(DateTime)">
				<ClickAsync Url="webservice.asmx" MethodName="DateToString" Success="
				function(data){
					$('#lblDate4').text('返回 ' + data + ', 类型为: ' + typeof data);
				}
				">
					<ParameterList>
						<je:Parameter Name="value" Type="Expression" Value="new Date()" DataType="Date" />
					</ParameterList>
				</ClickAsync>
			</je:Button>
			<p id="lblDate4"></p>
			<je:Button ID="cmdDate5" runat="server" Label="调用 DateTime GetDate()">
				<ClickAsync Url="webservice.asmx" MethodName="GetDate" Success="
				function(data){
					$('#lblDate5').text('返回 ' + data + ', 类型为: ' + typeof data + ', ' + $.panzer.formatDate(data, 'yyyy-MM-dd hh:mm:ss'));
				}
				">
				</ClickAsync>
			</je:Button>
			<p id="lblDate5"></p>
		</blockquote>
	</div>
	</form>
</body>
</html>
